<template>
    <div class="login-container">
      <h2>用户登录</h2>
      <form @submit.prevent="handleLogin">
        <input v-model="username" type="text" placeholder="用户名" required />
        <input v-model="password" type="password" placeholder="密码" required />
        <button type="submit">登录</button>
      </form>
      <p v-if="errorMsg">{{ errorMsg }}</p>
    </div>
  </template>
  
  <script setup>
  import { ref } from 'vue';
  import { useRouter } from 'vue-router';
  
  const router = useRouter();
  const username = ref('');
  const password = ref('');
  const errorMsg = ref('');
  
  const handleLogin = () => {
    if (username.value === 'admin' && password.value === '123456') {
      router.push('/dashboard');
    } else {
      errorMsg.value = '用户名或密码错误';
    }
  };
  </script>
  
  <style scoped>
  .login-container {
    max-width: 300px;
    margin: auto;
    text-align: center;
  }
  input {
    display: block;
    width: 100%;
    margin: 10px 0;
    padding: 8px;
  }
  button {
    width: 100%;
    padding: 8px;
    background-color: #42b983;
    color: white;
    border: none;
  }
  </style>
  